﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlatformSpawner : MonoBehaviour
{

    public Vector3 startSpawnPos;
    public Vector3 platformSpawnPosition;

    /// <summary>
    /// 生成平台数量
    /// </summary>
    private int spawnHorizontalPlatformCount = 10;
    private int spawnVerticalPlatformCount = 10;
    private ManagerVars vars;

    private void Awake()
    {
        vars = ManagerVars.GetManagerVars();
    }

    // Start is called before the first frame update
    void Start()
    {
        //生成平台
        platformSpawnPosition = startSpawnPos;
        for (int x = 0; x < spawnHorizontalPlatformCount; x++)
        {
            for (int y = 0; y < spawnVerticalPlatformCount; y++)
            {
                DecidePath(x,y);
            }
        }
        //生成人物
        GameObject go = Instantiate(vars.characterPre);
        go.transform.position = new Vector3(0,-0.0f,0);
    }

    private void DecidePath(int x, int y)
    {
        SpawnNormalPlatform(x,y);
    }

    /// <summary>
    /// 生成普通平台（单个）
    /// </summary>
    private void SpawnNormalPlatform(int x,int y)
    {
        platformSpawnPosition = new Vector3(startSpawnPos.x + (x - y) * vars.nextXPox, startSpawnPos.y + (x + y) * vars.nextYPox, x + y);

        GameObject go = ObjectPool.Instance.GetNormalPlatform();
        go.transform.position = platformSpawnPosition;
        //if (x == 1 && y == 2)
        //{
        //    testP = go;
        //    trans = go.transform;
        //    pos = trans.position;
        //}
        go.SetActive(true);


    }

    //private float shakeAmount = 0.06f;        // 阴影距离parent的半径  
    //private Transform trans;
    //private Vector3 pos;

    // Update is called once per frame
    void Update()
    {
        //if (testP != null)
        //{
        //    if (Time.frameCount % 5 == 0)
        //    {
        //        trans.position = pos + UnityEngine.Random.insideUnitSphere * shakeAmount;
        //    }
        //}
    }
}
